package com.springboot.erp.controller;

import com.springboot.erp.common.CommonResult;
import com.springboot.erp.entity.Outbound;
import com.springboot.erp.service.OutboundService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 出库单管理控制器
 * 处理出库单的创建、查询、更新和删除操作
 * @author z551199m
 */
@RestController
@RequestMapping("/sales/outbound")
@Slf4j
public class OutboundController {


    @Autowired
    private OutboundService outboundService;

    /**
     * 创建出库单
     */
    @PostMapping
    public CommonResult createOutbound(@RequestBody Outbound outbound) {
        log.info("创建出库单: {}", outbound);
        return new CommonResult(0, "success", outboundService.createOutbound(outbound));
    }

    /**
     * 根据ID查询出库单
     */
    @GetMapping("/{id}")
    public CommonResult selectOutboundById(@PathVariable Long id) {
        log.info("查询出库单: ID: {}", id);
        return new CommonResult(0, "success", outboundService.selectOutboundById(id));
    }

    /**
     * 更新出库单信息
     */
    @PutMapping
    public CommonResult updateOutbound(@RequestBody Outbound outbound) {
        log.info("更新出库单: {}", outbound);
        return new CommonResult(0, "success", outboundService.updateOutbound(outbound));
    }

    /**
     * 删除出库单记录
     */
    @DeleteMapping("/{id}")
    public CommonResult deleteOutbound(@PathVariable Long id) {
        log.info("删除出库单，ID: {}", id);
        return new CommonResult(0, "success", outboundService.deleteOutbound(id));
    }
}